package com.hangxiang.approval.controller;

import com.hangxiang.approval.common.*;
import com.hangxiang.approval.entity.Template;
import com.hangxiang.approval.service.TemplateService;
import com.hangxiang.approval.vo.TemplateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Template)表控制层
 *
 * @author makejava
 * @since 2020-11-23 18:07:08
 */
@RestController
@RequestMapping("template")
@Api(tags = "模板相关功能")
public class TemplateController {
    /**
     * 服务对象
     */
    @Resource
    private TemplateService templateService;

    /**
     * 通过主键查询单条数据
     *
     * @param common 主键
     * @return 单条数据
     */
    @PostMapping("selectOne")
    @ApiOperation(value = "通过主键查询单条数据详情")
    @ResponseBody
    public ResultBean selectOne(@RequestBody @Validated TemplateCommon common) {
        TemplateVo templateVo=templateService.selectById(common);
        return ResultBean.success(templateVo);
    }

    /**
     * @param
     * @return
     */
    @PostMapping("selectAllInfo")
    @ApiOperation(value = "通过类型查询多条数据")
    @ResponseBody
    public ResultBean selectAllInfo(@RequestBody @Validated TemplatePageCommon common) {
        return ResultBean.success(templateService.selectAllInfo(common));
    }

    @PostMapping("findTempInfo")
    @ApiOperation(value = "根据模板id查询所有审核人和抄送人")
    @ResponseBody
    public ResultBean findTempInfo(@RequestBody @Validated IntegerCommon common){
        return ResultBean.success(templateService.findTempInfo(common));
    }

    /**
     * 新增数据
     *
     * @param templateInsertCommon 实例对象
     * @return 实例对象
     */
    @PostMapping("insertTemplate")
    @ApiOperation(value = "添加数据")
    @ResponseBody
    public ResultBean insertTemplate(@RequestBody @Validated TemplateInsertCommon templateInsertCommon) {
        return ResultBean.success(templateService.insertTemplate(templateInsertCommon));
    }

    /**
     * 新增数据
     *
     * @param templateUpdateCommon 实例对象
     * @return 实例对象
     */
    @PostMapping("updateTemplate")
    @ApiOperation(value = "修改isDeleted就是删除")
    @ResponseBody
    public ResultBean update(@RequestBody @Validated TemplateUpdateCommon templateUpdateCommon) {
        return ResultBean.success(templateService.updateTemplate(templateUpdateCommon));
    }




}